/*
* @Date: 2020/4/28
* @Author: XueChengwu <xuechengwu@erayt.com>
* @Copyright: 2015-2019 Erayt, Inc.
* @Description: If you have some questions, please contact: xuechengwu@erayt.com.
*/

import React from 'react';
import { getUuid } from 'utils/common';
import $ from 'jquery'
import 'jquery-ui';
import ReactDOM from 'react-dom';
import componentsMap from "utils/componentsMap";

export default class {
  constructor(option, parent = null) {
    this.virtualDom = option.virtual; // 当前的虚拟节点
    this.realDom = option.real;
    this.props = option.props || []; // 当前组件需要的Props及说明
    this.parent = parent;         // 当前的父节点
    this.childs = [];             // 所有的子节点
    this.uuid = getUuid();        // 唯一节点
  }

  render() {
    $(this.realDom).empty();
    const div = document.createElement('div');
    const drag = document.createElement('span');
    $(drag).html('X');
    $(drag).addClass('drag');
    $(div).addClass('view-item-box');
    $(this.realDom).append(div);
    $(this.realDom).append(drag);
    $(this.realDom).attr('data-uuid', this.uuid);
    ReactDOM.render(
      React.createElement(componentsMap[$(this.realDom).attr('data-component')], { children: '标题' }),
      div
    );
  }
}
